<fieldset>
    <legend>条件搜索</legend>
    <form action="{:request()->url()}" autocomplete="off" class="layui-form layui-form-pane form-search" method="get" onsubmit="return false">
        <div class="layui-form-item layui-inline">
            <label class="layui-form-label">所属公司</label>
            <label class="layui-input-inline">
                <select class="layui-select" name="company_id" lay-filter="company_id">
                    <option value=''>-- 全部 --</option>
                    {foreach $companys as $k=>$v}
                    {if input('company_id') eq $v.id .''}
                    <option selected value="{$v.id}">{$v.name}</option>
                    {else}
                    <option value="{$v.id}">{$v.name}</option>
                    {/if}{/foreach}
                </select>
            </label>
        </div>

        <div class="layui-form-item layui-inline">
            <label class="layui-form-label">所属分类</label>
            <label class="layui-input-inline">
                <select class="layui-select" name="cate_id" id="cate_id" lay-filter="cate_id">
                    <option value=''>-- 全部 --</option>
                    {notempty name='cates'}
                    {foreach $cates as $k=>$v}
                    {if input('cate_id') eq $v.id .''}
                    <option selected value="{$v.id}">{$v.name}</option>
                    {else}
                    <option value="{$v.id}">{$v.name}</option>
                    {/if}{/foreach}
                    {/notempty}
                </select>
            </label>
        </div>

        <div class="layui-form-item layui-inline">
            <label class="layui-form-label">选择产品</label>
            <label class="layui-input-inline">
                <select class="layui-select" name="goods_id" id="goods_id">
                    <option value=''>-- 全部 --</option>
                    {notempty name='goodsList'}
                    {foreach $goodsList as $k=>$v}
                    {if input('goods_id') eq $v.id .''}
                    <option selected value="{$v.id}">{$v.name}</option>
                    {else}
                    <option value="{$v.id}">{$v.name}</option>
                    {/if}{/foreach}
                    {/notempty}
                </select>
            </label>
        </div>

        <div class="layui-form-item layui-inline pull-right">
            <button class="layui-btn layui-btn-primary" type="submit"><i class="layui-icon">&#xe615;</i> 搜 索</button>
        </div>
    </form>
</fieldset>

<script>
    window.form.render();
    $(function (){
        form.on('select(company_id)', function (data){
            let company_id = data.value;
            $.get("{:url('data/api.goods/getCate')}", {"company_id":company_id}, function (data){
                if (data.code == 1){
                    var cateHtml = '<option value="" selected>选择分类</option>';
                    $.each(data.data, function (index, val) {
                        cateHtml += '<option value="'+val.id+'">'+val.name+'</option>'
                    })

                    $("#cate_id").html(cateHtml)
                }

                form.render('select')
            })
        })

        form.on('select(cate_id)', function (data){
            let cate_id = data.value;
            $.get("{:url('data/api.goods/getGoods')}", {"cate_id":cate_id}, function (data){
                if (data.code == 1){
                    var goodsHtml = '<option value="" selected>选择产品</option>';
                    $.each(data.data, function (index, val) {
                        goodsHtml += '<option value="'+val.id+'">'+val.name+'</option>'
                    })

                    $("#goods_id").html(goodsHtml)
                }

                form.render('select')
            })
        })
    })

</script>